package com.jdkreader.concurrency.concurrent.delay;

import java.util.concurrent.DelayQueue;

/**
 * 延时任务消费者
 */
public class DelayedTaskConsumer implements Runnable{

    private DelayQueue<DelayedTask> dq;

    public DelayedTaskConsumer(DelayQueue<DelayedTask> queue){
        this.dq = queue;
    }

    public void run(){
        try{
            while(!Thread.interrupted()){
                dq.take().run();
            }
        }catch(InterruptedException e){
            e.printStackTrace();
        }
        System.out.println("DelayedTask Finished");
    }
}
